<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * @Date: 2022-06-17 16:20:10
 * @LastEditors: Sam
 * @LastEditTime: 2022-06-21 09:50:37
-->

<template>
  <div class="app-container">
      <el-card>
          <div slot="header" class="clearfix">
                <span>系统设置</span>
            </div>
              <el-tabs v-model="inc_type" @tab-click="handleClick" >
                <el-tab-pane label="基础设置" name="site_info" >
                    <el-form :model="site_info"  label-width="150px" style="width:460px">
                        <el-form-item :label="'文件上传附件大小(M)'" >
                             <el-input-number v-model.trim="site_info.attach_max" :min="1"></el-input-number>
                        </el-form-item>

                    </el-form>
                </el-tab-pane>

                 <el-tab-pane label="其他" name="other" >
                    <el-form  :model="other"  label-width="100px">
                         
                          
                    </el-form>
                </el-tab-pane>
            </el-tabs>
            <el-button type="primary"   icon="el-icon-check"  @click="submit" style="margin-left:150px">提交</el-button>
      </el-card>
  </div>

</template>

<script>
import { get_config,handle_config } from '@/api/settings'
import { getToken } from '@/utils/auth'



export default {
  name: 'Settings',
  data() {
    return {
      loading:true,
      dialogVisible:false,
      previewUrl:'',
      headerObj: {
        'Authorization': 'Bearer ' + getToken()
        },

  
    site_info:{
        site_name:'222',
        attach_max:5,
    },
    other:{
           order_expire_time:30,
        },
    inc_type : 'site_info',
    }
  },
  created() {
    this.fetchData()
  },

  methods: {

      
    fetchData() {
          get_config(this.inc_type).then(response => {
            this.loading = false;
            this.inc_type = response.data.inc_type;
            if(response.data.inc_type == 'site_info'){
              this.site_info = response.data.config;
            }else if(response.data.inc_type == 'other'){
              this.other = response.data.config;

            }
            
          }).catch(err => {
            console.log(err)
          })
        },
     handleClick(tab, event) {
         this.inc_type = tab.name;
         this.fetchData()
      },
    submit() {
      const thiz = this
        handle_config({
            inc_type: this.inc_type,
            site_info : this.site_info,
            other : this.other,
        }).then(response => {
          this.$message({
            message: '编辑成功',
            type: 'success',
            duration: 1500,
            onClose() {
              if (thiz.$refs.form !== undefined) {
                thiz.$refs.form.resetFields()
              }
            }
          })
        })
    }
  }
}
</script>
